﻿using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using SilverlightRestServices.Dispatcher;

namespace SilverlightRestServices.Description
{
    public class RestService : Attribute, IContractBehavior
    {
        public void AddBindingParameters(ContractDescription contractDescription, ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
            // Do Nothing
        }

        public void ApplyClientBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            foreach (ClientOperation op in clientRuntime.Operations)
            {
                op.Formatter = new RestMessageFormatter(endpoint.Address.Uri, op);
                op.SerializeRequest = true;
                op.DeserializeReply = true;
            }
        }

        public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
        {
            // Do Nothing
        }

        public void Validate(ContractDescription contractDescription, ServiceEndpoint endpoint)
        {
            // Do Nothing
        }
    }
}
